using System;
using System.Collections.Generic;
using System.Text;
using System.Net.NetworkInformation;

namespace NAst.Common
{
    /// <summary>
    /// Check if the DNS suffix of any network interface
    /// match a certain value
    /// </summary>
    class DnsSuffixTester : INetworkTest
    {
        string _expectedSuffix = "";
        #region INetworkTest Members

        public void Initialize(string stateName, System.Xml.XmlElement config)
        {
            _expectedSuffix = config.GetAttribute("suffix");
            if (string.IsNullOrEmpty(_expectedSuffix))
                _expectedSuffix = config.GetAttribute("value");
        }

        public bool Test()
        {
            foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces())
            {
                IPInterfaceProperties ipip = ni.GetIPProperties();
                if (ipip == null)
                    continue;
                if (string.Equals(ipip.DnsSuffix, _expectedSuffix))
                    return true;
            }

            return false;

        }

        #endregion
    }
}
